package com.boarsoft.flow.core;

import java.util.Map;
import java.util.concurrent.Future;

import com.boarsoft.flow.store.SimpleFlowPersister;

public interface SimpleFlowEngine {
	/**
	 * 
	 * @param flowId
	 * @return
	 */
	boolean exists(String flowId);

	/**
	 * 
	 * @param flowId
	 * @param data
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow start(String flowId, Object data) throws Throwable;

	/**
	 * 
	 * @param flowId
	 * @param data
	 * @param entry
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow start(String flowId, Object data, String entry) throws Throwable;

	/**
	 * 
	 * @param flowId
	 * @param id
	 * @param data
	 * @param entry
	 *            不指定entry时，将从头开始运行
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow start(String flowId, String id, Object data, String entry) throws Throwable;

	/**
	 * 
	 * @param flow
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow start(SimpleFlow flow) throws Throwable;

	/**
	 * 
	 * @param flow
	 * @param entry
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow start(SimpleFlow flow, String entry) throws Throwable;

	/**
	 * 
	 * @param flowId
	 * @param id
	 * @param exData
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow resume(String flowId, String id, Object exData) throws Throwable;

	/**
	 * 
	 * @param flow
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow resume(SimpleFlow flow) throws Throwable;

	/**
	 * 
	 * @param flowId
	 * @param exeId
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow getFlow(String flowId, String exeId) throws Throwable;

	/**
	 * 
	 * @param flow
	 * @return
	 */
	boolean stop(SimpleFlow flow);

	/**
	 * 
	 * @param flow
	 * @param exData
	 * @return
	 * @throws Throwable
	 */
	SimpleFlow resume(SimpleFlow flow, Object exData) throws Throwable;

	/**
	 * 
	 * @return
	 */
	String getCatalog();

	/**
	 * 异步执行流程
	 * 
	 * @param flow
	 */
	void execute(SimpleFlow flow);

	/**
	 * 异步执行流程
	 * 
	 * @param r
	 * @return future
	 */
	Future<SimpleFlow> submit(SimpleFlow r);

	/**
	 * 
	 * @param flowId
	 * @param id
	 * @param params
	 * @param entry
	 */
	void execute(String flowId, String id, Object params, String entry);

	/**
	 * 
	 * @param flowId
	 * @param id
	 * @param params
	 * @param entry
	 * @return
	 */
	Future<SimpleFlow> submit(String flowId, String id, Object params, String entry);

	/**
	 * 
	 * @param flowId
	 * @return
	 */
	SimpleFlow create(String flowId);

	/**
	 * 
	 * @param code
	 * @param id
	 * @param po
	 */
	void execute(String code, String id, Object po);

	/**
	 * 清除流程和对象缓存，暂停对外服务
	 */
	void close();

	/**
	 * 恢复对外服务
	 */
	void open();

	/**
	 * 
	 * @return
	 */
	Map<String, Map<String, SimpleFlow>> getTimeMap();

	/**
	 * 
	 * @return
	 */
	SimpleFlowPersister getPersister();

	/**
	 * 
	 */
	void watch();

	/**
	 * 
	 * @param flowId
	 */
	void watch(String flowId, int ratio);

	/**
	 * 
	 */
	void ignore();

	/**
	 * 取消对某种flow的采样
	 * 
	 * @param flowId
	 */
	void ignore(String flowId);

	/**
	 * 返回流程实例定义模板
	 * 
	 * @param flowId
	 * @return
	 */
	SimpleFlow getFlow(String flowId);

	/**
	 * 
	 * @param f
	 */
	void unmark(SimpleFlow f);

	/**
	 * 
	 * @param f
	 */
	void mark(SimpleFlow f);
}
